﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5.MaxSum2x2
{
    class MaxSum2x2
    {
        static void Main(string[] args)
        {
             int[,] matrix;
             StreamReader reader = new StreamReader(@"..\..\matrix.txt");
            using (reader)
            {
                string line = reader.ReadLine();
                int sizeOfMatrix = int.Parse(line);
                matrix = new int[sizeOfMatrix, sizeOfMatrix];
                for (int i = 0; i < sizeOfMatrix; i++)
                {
                    line = reader.ReadLine();
                    string[] elements = line.Split(' ');
                    for (int j = 0; j < sizeOfMatrix; j++)
                    {
                        matrix[i, j] = int.Parse(elements[j]);
                    }
                }
            }
            int maxSum = int.MinValue;
            for (int i = 0; i < matrix.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < matrix.GetLength(1) - 1; j++)
                {
                    int currentSum = matrix[i, j] + matrix[i + 1, j] + matrix[i, j + 1] + matrix[i + 1, j + 1];
                    if (maxSum < currentSum)
                    {
                        maxSum = currentSum;
                    }
                }

            }
            Console.WriteLine("Max sum : {0}", maxSum);
        }
    }
}
